using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using System.Collections.Generic;

namespace Pay.Service.AutoMapper {
	public class PaymentMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public PaymentMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<payment_dto, Payment>()
				.ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
				.ForMember(dest => dest.Settles, src => src.MapFrom(c => c.settles.ToJson()))
				.ForMember(dest => dest.Bank, src => src.MapFrom(c => c.bank.ToJson()))
				.ForMember(dest => dest.StartTime, src => src.MapFrom(c => c.start_time))
				.ForMember(dest => dest.EndTime, src => src.MapFrom(c => c.end_time))
				.ForMember(dest => dest.SingleQuota, src => src.MapFrom(c => c.single_quota))
				.ForMember(dest => dest.CardQuota, src => src.MapFrom(c => c.card_quota))
				.ForMember(dest => dest.IsOpen, src => src.MapFrom(c => c.is_open))
				.ForMember(dest => dest.IsRegister, src => src.MapFrom(c => c.is_register))
				.ForMember(dest => dest.IsMore, src => src.MapFrom(c => c.is_more));
			_cfg.CreateMap<Payment, payment_dto>()
				.ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
				.ForMember(dest => dest.settles, src => src.MapFrom(c => c.Settles.ToObject<List<settle_setting>>()))
				.ForMember(dest => dest.bank, src => src.MapFrom(c => c.Bank.ToObject<List<use_bank>>()))
				.ForMember(dest => dest.start_time, src => src.MapFrom(c => c.StartTime))
				.ForMember(dest => dest.end_time, src => src.MapFrom(c => c.EndTime))
				.ForMember(dest => dest.single_quota, src => src.MapFrom(c => c.SingleQuota))
				.ForMember(dest => dest.card_quota, src => src.MapFrom(c => c.CardQuota))
				.ForMember(dest => dest.is_open, src => src.MapFrom(c => c.IsOpen))
				.ForMember(dest => dest.is_register, src => src.MapFrom(c => c.IsRegister))
				.ForMember(dest => dest.is_more, src => src.MapFrom(c => c.IsMore));
		}
	}
}
